import 'package:flutter/material.dart';
import 'package:yyshort/common/model/video_model.dart';
import 'custom_icon_button.dart';

class IconButtonWidget extends StatelessWidget {
  final double? width;
  final double? height;

  // 定义各个图标的点击回调函数
  final VoidCallback? onStarTap;
  final VoidCallback? onHeartTap;
  final VoidCallback? onTvTap;
  final VoidCallback? onArrowTap;
  final bool isShowChooseIcon;

  final VideoModel? videoModel;

  const IconButtonWidget({
    Key? key,
    this.width,
    this.height,
    this.onStarTap, // 星星图标点击回调
    this.onHeartTap, // 爱心图标点击回调
    this.onTvTap, // TV图标点击回调
    this.onArrowTap, // 箭头图标点击回调
    this.videoModel,

    this.isShowChooseIcon = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final double tempheight = 32.0;
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        // CustomIconButton(
        //   normalAsset: 'assets/images/star_normal.png',
        //   selectedAsset: 'assets/images/star_selected.png',
        //   onTap: () {
        //     // 先执行内部逻辑（如果有）

        //   },
        // ),

        // 3. 仅外部控制状态（禁用内部切换）
        CustomIconButton(
          normalAsset: 'assets/images/star_normal.png',
          selectedAsset: 'assets/images/star_selected.png',
          isSelected: videoModel?.isCollect as int == 1, // 从外部状态获取
          enableToggle: false, // 禁用点击切换
          onTap: (isSelected) {
            // 仅响应点击，状态由外部控制
            print('星星图标被点击（内部）');
            // 再调用外部传入的回调
            if (onStarTap != null) {
              onStarTap!();
            }
          },
        ),

        SizedBox(height: tempheight),
        CustomIconButton(
          normalAsset: 'assets/images/heart_normal.png',
          selectedAsset: 'assets/images/heart_selected.png',
          isSelected: videoModel?.isLike as int == 1, // 从外部状态获取
          enableToggle: false, // 禁用点击切换
          onTap: (isSelected) {
            // 仅响应点击，状态由外部控制
            print('爱心图标被点击（内部）');
            if (onHeartTap != null) {
              onHeartTap!();
            }
          },
        ),

        Visibility(
          visible: isShowChooseIcon,
          child: SizedBox(height: tempheight),
        ),

        Visibility(
          visible: isShowChooseIcon,
          child: CustomIconButton(
            normalAsset: 'assets/images/tv_normal.png',
            selectedAsset: 'assets/images/tv_normal.png',
            onTap: (isSelected) {
              print('TV 图标被点击（内部）');
              if (onTvTap != null) {
                onTvTap!();
              }
            },
          ),
        ),

        SizedBox(height: tempheight),
        CustomIconButton(
          normalAsset: 'assets/images/arrow_normal.png',
          selectedAsset: 'assets/images/arrow_normal.png',
          onTap: (isSelected) {
            print('箭头图标被点击（内部）');
            if (onArrowTap != null) {
              onArrowTap!();
            }
          },
        ),
      ],
    );
  }
}
